package gonz.common;

import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Waiter {
    public static final Logger log = Logger.getLogger(Waiter.class);
    public static final long waitInterval = 30;//sec

    public static WebElement waitElement(WebDriver webDriver, final By by) {
        WebElement webElement = (new WebDriverWait(webDriver, waitInterval))
                .until(new ExpectedCondition<WebElement>() {
                    @Override
                    public WebElement apply(WebDriver d) {
                        return d.findElement(by);
                    }
                });
        log.debug(by + " element has been found.");
        return webElement;
    }
}
